package com.parktech.sun.domain.model.addressbook;

import com.parktech.sun.domain.model.BaseEntity;
import com.parktech.sun.domain.model.system.User;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;
import java.util.HashSet;
import java.io.Serializable;

/**
 * User: Think
 * Date: 2010-12-20
 * Time: 1:56:41
 */
@Entity
public class ContactGroup implements Serializable {
    private Long id;
    private String name;
    private Date createDatetime = new Date();
    private Date updateDatetime = new Date();
    private User creator;
    private User modifier;
    private String description;
    private Set<ContactMember> contactMembers = new HashSet<ContactMember>();

    @Column(name = "name", length = 66, nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "create_datetime", nullable = false)
    public Date getCreateDatetime() {
        return createDatetime;
    }

    public void setCreateDatetime(Date createDatetime) {
        this.createDatetime = createDatetime;
    }

    @Column(name = "update_datetime", nullable = false)
    public Date getUpdateDatetime() {
        return updateDatetime;
    }

    public void setUpdateDatetime(Date updateDatetime) {
        this.updateDatetime = updateDatetime;
    }

    @Column(name = "description", length = 66)
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE },
     fetch = FetchType.LAZY, mappedBy="contactGroups")
    public Set<ContactMember> getContactMembers() {
        return contactMembers;
    }

    public void setContactMembers(Set<ContactMember> contactMembers) {
        this.contactMembers = contactMembers;
    }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne
    @JoinColumn(name = "creator_id")
    public User getCreator() {
        return creator;
    }

    public void setCreator(User creator) {
        this.creator = creator;
    }

    @ManyToOne
    @JoinColumn(name = "modifier_id")
    public User getModifier() {
        return modifier;
    }

    public void setModifier(User modifier) {
        this.modifier = modifier;
    }
}
